package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.vo.RoleVo;
import com.cskaoyan.market.service.MarketRoleService;
import com.cskaoyan.market.service.impl.MarketRoleServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * ClassName: AdminSystemController
 * Package: com.cskaoyan.market.controller
 * Date: 2023/5/6 - 17:49
 * Description:
 */
@WebServlet("/admin/role/*")
public class AdminRoleController extends HttpServlet {
    MarketRoleService marketRoleService = new MarketRoleServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String requestURI = req.getRequestURI();
        String replace = requestURI.replace(req.getContextPath() + "/admin/role/", "");
        switch (replace) {
            case "options":
                options(req, resp);
                break;
        }
    }

    private void options(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        List<RoleVo> roleVos = marketRoleService.options();
        Object o = ResponseUtil.okList(roleVos);
        resp.getWriter().println(JacksonUtil.getObjectMapper().writeValueAsString(o));
    }
}
